package net.ufrog.common.app;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;

/**
 * @author ultrafrog, ufrog.net@gmail.com
 * @version 0.1, 2017-07-06
 * @since 0.1
 */
public class PropertiesBeans {

    private static Map<Class<?>, Map<Field, PropertiesValue>> mmPropertiesValue = new HashMap<>();

    /**
     * 读取属性内容映射
     *
     * @param requestType 请求类型
     * @return 属性内容映射
     */
    public static Map<Field, PropertiesValue> getPropertiesValues(Class<?> requestType) {
        if (!mmPropertiesValue.containsKey(requestType)) {
            Map<Field, PropertiesValue> mPropertiesValue = new HashMap<>();
            Stream.of(requestType.getDeclaredFields()).filter(field -> field.getAnnotation(PropertiesValue.class) != null).forEach(field -> mPropertiesValue.put(field, field.getAnnotation(PropertiesValue.class)));
            mmPropertiesValue.put(requestType, mPropertiesValue);
        }
        return mmPropertiesValue.get(requestType);
    }
}
